/**根据给的对象，添加execution方法 */
type WithExecution<T> = T extends (...args: infer A) => infer R
  ? ((...args: A) => WithExecution<R>) & { execution: () => Promise<R> }
  : T extends object
  ? { [K in keyof T]: WithExecution<T[K]> } & { execution: () => Promise<T> }
  : T & { execution: () => Promise<T> }

/**部分可选 */
type MakePropertyOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>

/**选取修改类型 */
type PickModify<T, K extends keyof T, M> = {
  [P in K]: M
}

/**
 * 深度可选工具类型
 */
type DeepPartial<T> = T extends object
  ? { [K in keyof T]?: DeepPartial<T[K]> }
  : T

/**去掉联合类型对象中的id */
type DistributiveOmit<T, K extends PropertyKey> =
  T extends any ? Omit<T, K> : never

export type {
  WithExecution,
  MakePropertyOptional,
  PickModify,
  DeepPartial,
  DistributiveOmit,
}
